package com.benshanyang.transformer;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class TestFragment extends Fragment {

    private int mParam1 = 0;
    private int mParam2 = 0;
    private String mParam3 = "";
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private static final String ARG_PARAM3 = "param3";
    private static final int[] colors = {0xFF00BE9E, 0xFF00D896, 0xFF0097D5, 0xFFA555B0, 0xFF2B475B, 0xFFFF9F40, 0xFFE25527, 0xFFD13834};


    public TestFragment() {
        // Required empty public constructor
    }

    public static TestFragment newInstance(int param1, int param2, String param3) {
        TestFragment fragment = new TestFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PARAM1, param1);
        args.putInt(ARG_PARAM2, param2);
        args.putString(ARG_PARAM3, param3);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getInt(ARG_PARAM1);
            mParam2 = getArguments().getInt(ARG_PARAM2);
            mParam3 = getArguments().getString(ARG_PARAM3);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_test, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        TextView textView = (TextView) view.findViewById(R.id.tv_text);
        textView.setText(" Fragment - " + (mParam1 + 1) + "\n我是" + (mParam2 == 0 ? "ViewPager" : "ViewPager2") + " 左右滑动我切换页面" + "\n切换动画:" + mParam3);
        textView.setBackgroundColor(colors[mParam1 % (colors.length)]);
    }
}